package cn.bs.busuo.front.content.controller;

import cn.bs.busuo.common.pojo.authentication.CurrentPrincipal;
import cn.bs.busuo.common.web.JsonResult;
import cn.bs.busuo.front.content.pojo.param.HotelArticleUpDateParam;
import cn.bs.busuo.front.content.pojo.param.SightArticleAddNewParam;
import cn.bs.busuo.front.content.pojo.param.SightArticleUpDateParam;
import cn.bs.busuo.front.content.pojo.vo.UserContentSightArticleByIdVO;
import cn.bs.busuo.front.content.service.UserSightArticleService;
import cn.hutool.db.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;

/**
 * @author: Feng
 * @since: 2023/12/8
 */
@RestController
@Slf4j
@RequestMapping("/user/content/sightArticle")
@Api(tags = "7.用户景点文章")
public class UserSightArticleController {
    @Autowired
    private UserSightArticleService userSightArticleService;

    @PostMapping("/addNewSightArticle/{id}")
    @PreAuthorize("hasAuthority('/account/user/normal')")
    @ApiOperation("发布景点文章")
    @ApiOperationSupport(order = 100)
    public JsonResult addNewSightArticle(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,
                                         @Valid SightArticleAddNewParam sightArticleAddNewParam,@PathVariable @ApiIgnore("id") Long id) {
        userSightArticleService.addNewSightArticle(currentPrincipal, sightArticleAddNewParam,id);
        return JsonResult.ok();
    }

    @PostMapping("/deleteSightArticle")
    @PreAuthorize("hasAuthority('/account/user/normal')")
    @ApiOperation("删除景点文章")
    @ApiOperationSupport(order = 200)
    public JsonResult deleteSightArticle(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,Long id) {
        userSightArticleService.deleteArticle(currentPrincipal,id);
        return JsonResult.ok();
    }

    @GetMapping("/selectSightById/{id}")
    @PreAuthorize("hasAuthority('/account/user/normal')")
    @ApiOperation("根据景点Id查看景点文章")
    @ApiOperationSupport(order = 300)
    public JsonResult selectSightArticleById(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,@PathVariable @ApiIgnore("id") Long id) {
        return JsonResult.ok(userSightArticleService.selectSightArticleById(id));
    }

    @GetMapping("/selectSightArticleById/{id}")
    @PreAuthorize("hasAuthority('/account/user/normal')")
    @ApiOperation("查看景点文章详情")
    @ApiOperationSupport(order = 400)
    public JsonResult selectSightArticleDetailById(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,
                                         @PathVariable @ApiIgnore("id") Long id) { //
        return JsonResult.ok(userSightArticleService.selectSightArticleDetailById(id));
    }

    @PostMapping("/selectSightArticleById/upCount/{id}")
    @PreAuthorize("hasAuthority('/account/user/normal')")
    @ApiOperation("查看酒店文章详情并好评")
    @ApiOperationSupport(order = 500)
    public JsonResult hotelArticleDetailIncreaseUpCount(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,@PathVariable @ApiIgnore Long id) {
        userSightArticleService.increaseUpCount(id);
        return JsonResult.ok();
    }

    @PostMapping("/selectSightArticleById/downCount/{id}")
    @PreAuthorize("hasAuthority('/account/user/normal')")
    @ApiOperation("查看酒店文章详情并差评")
    @ApiOperationSupport(order = 600)
    public JsonResult hotelArticleDetailIncreaseDownCount(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,@PathVariable @ApiIgnore Long id) {
        userSightArticleService.increaseDownCount(id);
        return JsonResult.ok();
    }

    @GetMapping("/selectUserListSlightArticle")
    @PreAuthorize("hasAuthority('/account/user/normal')")
    @ApiOperation("查看自己的景点文章")
    @ApiOperationSupport(order = 700)
    public JsonResult selectUserListSlightArticle(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal) {
        return JsonResult.ok(userSightArticleService.selectUserListSlightArticle(currentPrincipal.getUsername()));
    }

    @PostMapping("/userListSightArticle/upDateSightArticle/{id}")
    @PreAuthorize("hasAuthority('/account/user/normal')")
    @ApiOperation("修改自己的酒店文章")
    @ApiOperationSupport(order = 800)
    public JsonResult upDateSightArticle(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal, @PathVariable @ApiIgnore Long id, SightArticleUpDateParam sightArticleUpDateParam) {
        userSightArticleService.upDateSightArticle(currentPrincipal.getUsername(),id,sightArticleUpDateParam);
        return JsonResult.ok();
    }
}
